// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class MF_QUERY_MFR_M04 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("10 MFE",10)]
  	    [HL7Field(HL7Version.v25, 10, HL7Repeat.False, HL7Required.True,"MFE")]
	    public MFE MFE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("11 CDM",11)]
  	    [HL7Field(HL7Version.v25, 11, HL7Repeat.False, HL7Required.True,"CDM")]
	    public CDM CDM {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("12 LCH",12)]
  	    [HL7Field(HL7Version.v25, 12, HL7Repeat.True, HL7Required.False,"LCH")]
	    public LCH[] LCH {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("13 PRC",13)]
  	    [HL7Field(HL7Version.v25, 13, HL7Repeat.True, HL7Required.False,"PRC")]
	    public PRC[] PRC {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			MFE = PopSegmentParseAndCheckRequired<MFE>(availableData, options, "MFE");
			CDM = PopSegmentParseAndCheckRequired<CDM>(availableData, options, "CDM");
			LCH = PopSegmentParseAndCheckRequiredArray<LCH>(availableData, options, "LCH");
			PRC = PopSegmentParseAndCheckRequiredArray<PRC>(availableData, options, "PRC");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isMFE = availableData.StartsWith("MFE", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("MFE", options.Version) || isMFE) {
				return isMFE;
			}
			bool isCDM = availableData.StartsWith("CDM", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("CDM", options.Version) || isCDM) {
				return isCDM;
			}
			bool isLCH = availableData.StartsWith("LCH", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("LCH", options.Version) || isLCH) {
				return isLCH;
			}
			bool isPRC = availableData.StartsWith("PRC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PRC", options.Version) || isPRC) {
				return isPRC;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "MF_QUERY";
			}
        }

        static MF_QUERY_MFR_M04() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(MF_QUERY_MFR_M04));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (MFE != null) {
			string segmentValue = MFE.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (CDM != null) {
			string segmentValue = CDM.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (LCH != null && LCH.Length > 0) {
			for (int i = 0; i < LCH.Length; i++) {
				string segmentValue = LCH[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (PRC != null && PRC.Length > 0) {
			for (int i = 0; i < PRC.Length; i++) {
				string segmentValue = PRC[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

